home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / amiga / animutil / dbuf / dbuff.c < prev   
Text File  |  1988-06-06  |  5KB  |  212 lines

  1.  
  2.     Hi - here are the double buffering routines you were interested in.
  3. They are very easy to use and as far as the memory meter on the Workbench
  4. title bar, they also return every byte they allocate. I also uploaded this
  5. to Programming if you don't get the whole thing.
  6.  
  7.     Drawbacks:
  8.  
  9.         a)  No message port. You have to roll your own.
  10.         b)  No depth arranging. Because I have to to LoadView() to
  11.             display the frame, you can't KEEP it in the background.
  12.         c)  More work for the programmer. (not too much though)
  13.  
  14.     Advantages:
  15.  
  16.         a)  No screen or windows needed.
  17.         b)  Fast - I don't call ReThinkDisplay() or MakeScreen().
  18.         c)  SHOULD work with an interlaced display (just add two
  19.             more FreeCprList(bmxSHF)'s into FreedbuffMem()).
  20.         d)  It works.
  21.         e)  It's free.
  22.  
  23.     I think the advantages outweigh the disadvantages. I hope you have
  24. fun with them, and if you have any questions don't hesitate to ask.
  25.  
  26. -Steve-
  27.  
  28. Quote of the day:
  29.  
  30.     "Dare to be gorgeous and unique. But don't ever be cryptic or otherwise
  31.     unfathomable. Make it unforgettably great."
  32.  
  33. Intuition Reference Manual, pg 231.
  34.  
  35. /*************************************************************
  36. **                                                          **
  37. **  This program was written by Steve Berry and             **
  38. **  is hereby placed firmly into the public domain.         **
  39. **  In otherwords, don't blame me if it breaks.             **
  40. **                                                          **
  41. **  File: dbuff.c                                           **
  42. **                                                          **
  43. **************************************************************/
  44.  
  45. #include "exec/types.h"
  46. #include "exec/exec.h"
  47. #include "intuition/intuition.h"
  48. #include "graphics/gels.h"
  49. #include "graphics/rastport.h"
  50.  
  51. struct ViewPort vp1;
  52. struct ViewPort vp2;
  53. struct RastPort rp;
  54. struct RasInfo ri;
  55. struct View view;
  56.  
  57. struct BitMap bm1;
  58. struct BitMap bm2;
  59.  
  60. extern void InitBitMap(),WaitBOVP(),MakeVPort(),LoadView(),InitRastPort();
  61. extern void InitVPort(),MrgCop(),FreeVPortCopLists(),FreeCprList();
  62. extern void FreeMem(),InitView();
  63. extern PLANEPTR AllocMem();
  64.  
  65. #define PLANESIZE 8000
  66. #define CHIPCLEAR MEMF_CHIP+MEMF_CLEAR+MEMF_PUBLIC
  67. #define DEPTH 4
  68. #define WIDTH 320
  69. #define HEIGHT 200
  70.  
  71. struct CopList *bm1LOF,*bm1SHF,*bm2LOF,*bm2SHF;
  72.  
  73. /*
  74. *
  75. * Procedure:
  76. *
  77. * Initdbuff();
  78. * while(not bored){
  79. *    draw into 1
  80. *    Display1()
  81. *    draw into 2
  82. *    Display2();
  83. * }
  84. * FreedbuffMem();
  85. *
  86. */
  87.  
  88. Initdbuff()
  89.  
  90. {
  91.     int i;
  92.  
  93.     for(i=0;i<DEPTH;i++){
  94.         bm1.Planes[i] = AllocMem(PLANESIZE,CHIPCLEAR);
  95.         bm2.Planes[i] = AllocMem(PLANESIZE,CHIPCLEAR);
  96.     }
  97.  
  98.     InitBitMap(&bm1,DEPTH,WIDTH,HEIGHT);
  99.     InitBitMap(&bm2,DEPTH,WIDTH,HEIGHT);
  100.  
  101.     ri.BitMap = &bm1;
  102.     ri.RxOffset = 0; ri.RyOffset = 0;
  103.     ri.Next = NULL;
  104.  
  105.     InitRastPort(&rp);
  106.  
  107.     rp.BitMap = &bm1;
  108.  
  109.     InitVPort(&vp1); InitVPort(&vp2);
  110.  
  111.     vp1.DWidth = WIDTH; vp1.DHeight = HEIGHT; vp1.DxOffset = 0;
  112.     vp1.DyOffset = 0; vp1.RasInfo = &ri; vp1.Next = &vp2;
  113.  
  114.     vp2.DWidth = WIDTH; vp2.DHeight = HEIGHT; vp2.DxOffset = 0;
  115.     vp2.DyOffset = 0; vp2.RasInfo = &ri; vp2.Next = NULL;
  116.  
  117.     InitView(&view);
  118.  
  119.     view.ViewPort = &vp1;
  120.  
  121.     Disp(&view);
  122.  
  123.     bm1LOF = view.LOFCprList;
  124.     bm1SHF = view.SHFCprList;
  125.  
  126.     view.LOFCprList = 0;
  127.     view.SHFCprList = 0;
  128.  
  129.     ri.BitMap = &bm2;
  130.     rp.BitMap = &bm2;
  131.  
  132.     Disp(&view);
  133.  
  134.     bm2LOF = view.LOFCprList;
  135.     bm2SHF = view.SHFCprList;
  136.  
  137.     view.LOFCprList = bm1LOF;
  138.     view.SHFCprList = bm1SHF;
  139.  
  140.     ri.BitMap = &bm1;
  141.     rp.BitMap = &bm1;
  142. }
  143.  
  144. /*
  145. *
  146. * This function Displays bitplane 1 and
  147. * set's up for drawing into bitplane 2.
  148. *
  149. */
  150.  
  151. Display1()
  152. {
  153.     Forbid();
  154.     WaitBOVP(&vp2);
  155.     Disp(&view);
  156.     Permit();
  157.  
  158.     view.LOFCprList = bm2LOF;
  159.     view.SHFCprList = bm2SHF;
  160.  
  161.     ri.BitMap = &bm2;
  162.     rp.BitMap = &bm2;
  163. }
  164.  
  165. /*
  166. *
  167. * This function Displays bitplane 2 and
  168. * set's up for drawing into bitplane 1.
  169. *
  170. */
  171.  
  172. Display2()
  173. {
  174.     Forbid();
  175.     WaitBOVP(&vp1);
  176.     Disp(&view);
  177.     Permit();
  178.  
  179.     view.LOFCprList = bm1LOF;
  180.     view.SHFCprList = bm1SHF;
  181.  
  182.     ri.BitMap = &bm1;
  183.     rp.BitMap = &bm1;
  184. }
  185.  
  186. Disp(v)
  187. struct View *v;
  188. {
  189.  
  190.     MakeVPort(v,&vp1);
  191.     MakeVPort(v,&vp2);
  192.     MrgCop(v);
  193.     LoadView(v);
  194.  
  195. }
  196.  
  197. /* got to free up space on the other bitmap */
  198.  
  199. FreedbuffMem()
  200. {
  201.     int i;
  202.     for(i=0;i<DEPTH;i++)
  203.         FreeMem(bm1.Planes[i],PLANESIZE);
  204.     for(i=0;i<DEPTH;i++)
  205.         FreeMem(bm2.Planes[i],PLANESIZE);
  206.  
  207.     FreeVPortCopLists(&vp1);
  208.     FreeVPortCopLists(&vp2);
  209.     FreeCprList(bm1LOF); /* should do FreeCpr for SHF if LACE */
  210.     FreeCprList(bm2LOF);
  211. }